#include "ConnectElementHleper.h"

using namespace SG::DataStructure::Common;
using SG::DataStructure::FEM::ShellSecMaterialConstant;
using SG::DBManager::DBServiceFactorySP;
using SG::FEMSolver::Element::ShellSectionParser;
using SG::FEMSolver::Element::ConnectElementHleper;

ConnectElementHleper::ConnectElementHleper ()
: m_parser{std::make_shared<ShellSectionParser>()}
{

}

ConnectElementHleper::~ConnectElementHleper ()
{
    m_ThicknessTable.clear ();
}

Real ConnectElementHleper::ComputeShellSecThickness (const DBServiceFactorySP dbServiceFactory, Id pId)
{
    // 截面数据是否被缓存
    auto it = m_ThicknessTable.find (pId);
    if (it != m_ThicknessTable.end ())
    {
        return it->second;
    }

    ShellSecMaterialConstant secConstant;
    std::vector<Real> eleMatAxis{1.0, 0.0};
    // 必须提高到更高的模块层级
    Status     status = m_parser->Compute (dbServiceFactory, pId, false, eleMatAxis, _OUT secConstant);
    if (Status::STATUS_Failure == status)
    {
        assert (0 && "can't find section\n");
    }

    m_ThicknessTable[pId] = secConstant.m_t;
    
    return secConstant.m_t;
}